package com.example.personnel_management_system.controller;

import com.example.personnel_management_system.controller.ex.*;
import com.example.personnel_management_system.service.ex.InsertException;
import com.example.personnel_management_system.service.ex.ServiceException;
import com.example.personnel_management_system.util.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;

public class BaseController {
    public static final Integer ok=200;
    @ExceptionHandler({ServiceException.class, FileUploadException.class})
    public Result<Void> handleException(Throwable e){
        Result<Void>result=new Result<>(e);
        result.setStatus(4000);
        if(e instanceof InsertException){
            result.setStatus(5000);
            result.setMessage("增加用户时错误");
        }else if (e instanceof FileEmptyException) {
            result.setStatus(6000);
        } else if (e instanceof FileSizeException) {
            result.setStatus(6001);
        } else if (e instanceof FileTypeException) {
            result.setStatus(6002);
        } else if (e instanceof FileStateException) {
            result.setStatus(6003);
        } else if (e instanceof FileUploadIOException) {
            result.setStatus(6004);
        }
        return result;
    }
}
